﻿using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using SharedResources.Model;
using SharedResources.Utilities;
using SharedResources.ViewModel;

namespace LayersModule.ViewModel
{
    public class LayerStackViewModel : BaseViewModel
    {

        public LayerStackViewModel() 
        {
            UnderlyingData.OnDatasetAdded += delegate //event to fire when dataset is available
                                                 {
                                                     OnPropertyChanged("SelectableLayers");
                                                 };
        }

        public ObservableCollection<SelectableDataset> SelectableLayers //get the selectable layers from the dataset
        {
            get
            {
                if(UnderlyingData.SelectableData == null)
                {
                    return null;
                }
                var returnCollection = new ObservableCollection<SelectableDataset>();
                foreach (var selectedTuple in UnderlyingData.SelectableData)
                {
                    returnCollection.Add(selectedTuple.Item2);
                }
                return returnCollection;
            }
        }

        private RelayCommand _rightClickLayerOptions;
        public ICommand RightClickLayerOptions //right click command
        {
            get
            {
                return _rightClickLayerOptions = MakeCommandSafely(_rightClickLayerOptions, () => OpenLayersOptions());
            }
        }

        private void OpenLayersOptions() //right click command logic
        {
            MessageBox.Show("test menu");
            //thinking make context menu and pass string,action pairs and then onclick on menu item run the corresponding action
            //maybe have a class that extends context menu
        }

    }
}
